package org.apache.ibatis.ibator.generator.ibatis3.pagination;

import org.apache.ibatis.ibator.api.IntrospectedTable;
import org.apache.ibatis.ibator.api.dom.xml.XmlElement;
import org.apache.ibatis.ibator.config.IbatorContext;
import org.apache.ibatis.ibator.generator.ibatis3.pagination.xmlmapper.MysqlPaginationGenerator;
import org.apache.ibatis.ibator.generator.ibatis3.pagination.xmlmapper.SelectByExampleWithBLOBsPaginationGenerator;
import org.apache.ibatis.ibator.generator.ibatis3.pagination.xmlmapper.SelectByExampleWithoutBLOBsPaginationtGenerator;
import org.apache.ibatis.ibator.generator.ibatis3.xmlmapper.elements.AbstractXmlElementGenerator;

/**
 * 生成分页相关代码
 * 
 * @author liwb 2016年1月27日 下午7:57:57
 */
public class Ibatis3PaginationGenerator {

    public void xmlMySqlGenerator(IbatorContext ibatorContext,
            IntrospectedTable introspectedTable, XmlElement element) {
        AbstractXmlElementGenerator mysqlPaginationLimitGenerator = new MysqlPaginationGenerator();
        mysqlPaginationLimitGenerator.setIbatorContext(ibatorContext);
        mysqlPaginationLimitGenerator.setIntrospectedTable(introspectedTable);
        mysqlPaginationLimitGenerator.addElements(element);
        if (introspectedTable.getRules().generateSelectByExampleWithoutBLOBs()) {
            AbstractXmlElementGenerator examplePagination = new SelectByExampleWithoutBLOBsPaginationtGenerator();
            examplePagination.setIbatorContext(ibatorContext);
            examplePagination.setIntrospectedTable(introspectedTable);
            examplePagination.addElements(element);
        }
        if (introspectedTable.getRules().generateSelectByExampleWithBLOBs()) {
            AbstractXmlElementGenerator examplePagination = new SelectByExampleWithBLOBsPaginationGenerator();
            examplePagination.setIbatorContext(ibatorContext);
            examplePagination.setIntrospectedTable(introspectedTable);
            examplePagination.addElements(element);
        }
    }

}
